﻿<!DOCTYPE html>
<html>
<head>
<title>自学考试</title>
<style type="text/css">
	.passed {
		background-color: #79b900;
	}
</style>
<script src="/js/layout.js" type="text/javascript"></script>
<script type="text/javascript">
	function STEViewModel() {
		var self = this;

		self.courses = ko.observableArray([]);
		var sql = [];
		sql.push('SELECT c.*, cn.Name NatureName, cm.Name MethodName, p.Score, p.ExamPeriod FROM Courses c');
		sql.push('LEFT JOIN CourseNatures cn ON c.NatureID=cn.ID');
		sql.push('LEFT JOIN CourseMethods cm ON c.MethodID=cm.ID');
		sql.push('LEFT JOIN Passed p ON c.Code=p.CourseCode');
		jsonrpc.invoke({
		    method: 'sqlite',
		    params: {
		        file: './db/ste.db',
		        sql: sql.join(' ')
		    },
		    success: function (data) {
		        self.courses(data.result);
		    }
		});

		self.materials = ko.observableArray([]);
		sql = [];
		sql.push('SELECT m.*, c.Name CourseName, p.Name PublisherName FROM Materials m');
		sql.push('LEFT JOIN Courses c ON m.CourseCode=c.Code');
		sql.push('LEFT JOIN CourseNatures cn ON c.NatureID=cn.ID');
		sql.push('LEFT JOIN CourseMethods cm ON c.MethodID=cm.ID');
		sql.push('LEFT JOIN Publishers p ON m.PublisherID=p.ID');
		jsonrpc.invoke({
		    method: 'sqlite',
		    params: {
		        file: './db/ste.db',
		        sql: sql.join(' ')
		    },
		    success: function (data) {
		        self.materials(data.result);
		    }
		});
	}

	$(function() {
		$('#tabs').tabs();
		ko.applyBindings(new STEViewModel());
	});
</script>
</head>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">专业课程</a></li>
			<li><a href="#tabs-2">教材</a></li>
		</ul>
		<div id="tabs-1">
			<table class="table">
				<thead>
					<tr>
						<th>序号</th>
						<th>课程代码</th>
						<th>课程名称</th>
						<th>课程性质</th>
						<th>学分</th>
						<th>考核方式</th>
                        <th>考试情况</th>
					</tr>
				</thead>
                <tbody data-bind="foreach:courses">
                    <tr data-bind="css:{passed:Score}">
                        <td data-bind="text:$index()+1"></td>
                        <td data-bind="text:Code"></td>
                        <td data-bind="text:Name"></td>
                        <td data-bind="text:NatureName"></td>
                        <td data-bind="text:Credit"></td>
                        <td data-bind="text:MethodName"></td>
                        <td data-bind="text:Score?('成绩：'+Score+'，考试期：'+ExamPeriod):''"></td>
                    </tr>
                </tbody>
			</table>
		</div>
		<div id="tabs-2">
        	<table class="table">
				<thead>
					<tr>
						<th>序号</th>
						<th>课程代码</th>
						<th>课程名称</th>
						<th>教材名称</th>
						<th>出版社</th>
						<th>版本</th>
                        <th>作者</th>
                        <th>教材开始使用日期</th>
                        <th>教材结束使用日期</th>
					</tr>
				</thead>
                <tbody data-bind="foreach:materials">
                    <tr>
                        <td data-bind="text:$index()+1"></td>
                        <td data-bind="text:CourseCode"></td>
                        <td data-bind="text:CourseName"></td>
                        <td data-bind="text:Name"></td>
                        <td data-bind="text:PublisherName"></td>
                        <td data-bind="text:Version"></td>
                        <td data-bind="text:Authors"></td>
                        <td data-bind="text:BeginDate"></td>
                        <td data-bind="text:EndDate"></td>
                    </tr>
                </tbody>
			</table>
        </div>
	</div>
</body>
</html>
